import React, { Component } from 'react';
import { Select} from 'antd';
const { Option } = Select;

class SelectCom extends Component {
    constructor(props) {
        super(props);
        this.field = this.props['field']
    	this.state = this.setParamsData(this.props)
    }
    
    componentWillMount() {
    
    }
    
    componentDidMount() {
    
    }
    setParamsData(config) {
    	let fetch = {} // 保存提交数据
    	const { field, defaultValue } = config
    	fetch[field] = defaultValue || ''     // 设置默认值
    	return fetch
    }
    onSelectChange(val) {  //  val 是选中的value值val
    	this.state[this.field] = val
    	this.setState({...this.state})
    }
    getFetchData() {
    	let data = this.state
    	return data
    }
	
    render() {
		const { width, options=[] } = this.props
		const optionNode = options.map( (item,index) => {
			return <Option key={index} value={ item.value} >{ item.label }</Option>
		})
        return (
			<Select value={this.state[this.field]} onChange={this.onSelectChange.bind(this)} style={{ width }} { ...this.props } >
				{ optionNode }
			 </Select>
        );
    }
	
}

export default SelectCom;
